//BusClearingCcbpayModel
//2020-08-11 17:33:27

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type BusClearingCcbpayModel struct {
	Model *base.Model
	Field BusClearingCcbpayModelField
}

//表字段
type BusClearingCcbpayModelField struct {
	T_table             string `default:"bus_clearing_ccbpay"`
	F_id                string `default:"id"`
	F_bus_id            string `default:"bus_id"`
	F_order_no          string `default:"order_no"`
	F_batch_no          string `default:"batch_no"`
	F_amount            string `default:"amount"`
	F_depository_amount string `default:"depository_amount"`
	F_usable_amount     string `default:"usable_amount"`
	F_status            string `default:"status"`
	F_error_msg         string `default:"error_msg"`
	F_agent_time        string `default:"agent_time"`
	F_merchant_id       string `default:"merchant_id"`
	F_account_name      string `default:"account_name"`
	F_account_no        string `default:"account_no"`
	F_card_name         string `default:"card_name"`
	F_card_no           string `default:"card_no"`
	F_card_bank_name    string `default:"card_bank_name"`
	F_card_bank_no      string `default:"card_bank_no"`
	F_create_time       string `default:"create_time"`
}

//初始化
func (b *BusClearingCcbpayModel) Init(ormer ...orm.Ormer) *BusClearingCcbpayModel {
	functions.ReflectModel(&b.Field)
	b.Model = base.NewModel(b.Field.T_table, ormer...)
	return b
}

//新增数据
func (b *BusClearingCcbpayModel) Insert(data map[string]interface{}) int {
	result, _ := b.Model.Data(data).Insert()
	return result
}

// 根据busId和状态查询记录
func (b *BusClearingCcbpayModel) FindByBusIdAndStatus(busId, status interface{}) map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_bus_id: busId,
		b.Field.F_status: status,
	}).Find()
}

// 根据id和状态更新记录
func (b *BusClearingCcbpayModel) UpdateByIdAndStatus(id, status interface{}, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_id:     id,
		b.Field.F_status: status,
	}).Data(data).Update()
}

// 根据状态查询记录
func (b *BusClearingCcbpayModel) GetListsByStatus(status, count int) []map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_status: status,
	}).Limit(0, count).Select()
}

// 根据busIds和状态批量更新记录
func (b *BusClearingCcbpayModel) UpdateByBusIdsAndStatus(busIds []int, status int, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_bus_id: []interface{}{"in", busIds},
		b.Field.F_status: status,
	}).Data(data).Update()
}

// 根据Ids和状态批量更新记录
func (b *BusClearingCcbpayModel) UpdateByIdsAndStatus(Ids []string, status int, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_id:     []interface{}{"in", Ids},
		b.Field.F_status: status,
	}).Data(data).Update()
}

// 根据orderNo,batchNo,status,merchantId更新记录
func (b *BusClearingCcbpayModel) UpdateResultAgent(orderNo, batchNo, status, merchantId interface{}, data map[string]interface{}) (int, error) {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_order_no:    orderNo,
		b.Field.F_batch_no:    batchNo,
		b.Field.F_status:      status,
		b.Field.F_merchant_id: merchantId,
	}).Data(data).Update()
}

// 根据orderNo,batchNo,status,merchantId查询记录
func (b *BusClearingCcbpayModel) FindResultAgent(orderNo, batchNo, status, merchantId interface{}) map[string]interface{} {
	return b.Model.Where(map[string]interface{}{
		b.Field.F_order_no:    orderNo,
		b.Field.F_batch_no:    batchNo,
		b.Field.F_status:      status,
		b.Field.F_merchant_id: merchantId,
	}).Find()
}
